﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace AgileShare.Framework.Library.Helpers
{
    public sealed class SingletonProvider<T> where T : class
    {
        static T _Instance;
        static readonly object lockHelper = new object();
        static SingletonProvider() { }
        /// <summary>  
        /// 返回单例对象  
        /// </summary>  
        public static T Instance
        {
            get
            {
                lock (lockHelper)
                {
                    if (_Instance == null)
                    {
                        _Instance = typeof(T).InvokeMember(typeof(T).Name, BindingFlags.CreateInstance | BindingFlags.Instance
                            | BindingFlags.NonPublic | BindingFlags.Public, null, null, null) as T;
                    }
                    return _Instance;
                }
            }
        }
    }  
}
